import java.util.Arrays;

public class J092501 {
    public static void duplicateZeros(int[] arr) {
        int len = arr.length;
        int cur = 0;
        int dest = -1;
        while(cur < len){
            if(arr[cur] == 0){
                dest += 2;
            }else{
                dest++;
            }
            if(dest >= len - 1){
                break;
            }
            cur++;
        }
        if(dest >= len){
            arr[len - 1] = 0;
            dest -= 2;
            cur--;
        }
        while(cur >= 0){
            if(arr[cur] == 0){
                arr[dest--] = 0;
                arr[dest--] = 0;
            }else{
                arr[dest--] = arr[cur];
            }
            cur--;
        }
    }
    public static void main(String[] args) {
        int[] nums = new int[]{8,5,0,0,0,0,7};
        duplicateZeros(nums);
        System.out.println(Arrays.toString(nums));
    }
}
